<template>
  <div>
    <el-row>
      <el-col>
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
          <el-form-item>
            <el-input v-model="formInline.menusName" placeholder="请输入菜名"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="search" @click="onSubmit">搜索</el-button>
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="8" v-for="(o, index) in List" style="margin:5px">
        <el-card :body-style="{ padding: '0px' }">
          <img :src="o.imageUrl" :alt="o.food" class="image">
          <div style="padding: 14px;">
            <span><strong>{{o.name}}</strong></span>
            <div class="bottom clearfix">
              <time class="time">{{ o.food }}</time>
              <el-button type="text" class="button" @click="onClickMenusInfo(o)">详细...</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <common-mask :Show="showDetail" @onClose="onClose">
      <div>
        <p>{{Info.name}}</p>
        <p>{{Info.food}}</p>
        <p><img :src="Info.imageUrl" /></p>
        <p v-html="Info.message"></p>
      </div>
    </common-mask>
  </div>
</template>

<script>
import services from './services.js'

export default {
  data(){
    return {
      formInline: {
        menusName: ''
      },
      showDetail: false,
      currentDate: new Date(),
      List: [],
      Info: {
        id: 0,
        count: 0,
        name: '',
        food: '',
        img: '',
        description: '',
        message: ''
      }
    }
  },
  mounted(){
    var id = this.$route.params.id
    services.MenusList(id, (result) => {
      this.List = result
    })
  },
  methods: {
    onClickMenusInfo(item) {
      this.onShow()
      // this.$router.push(`/MenusInfo/${item.id}`)
      services.MenusInfo(item.id, (result) => {
        Object.assign(this.Info, result)
      })
    },
    onShow(){
      this.showDetail = true
    },
    onClose(){
      this.showDetail = false
    },
    onSubmit(){
      var name = this.formInline.menusName
      services.SearchMenus(name, (result) => {
        this.List = result
      })
    }
  }
}
</script>

<style>
  .time {
    font-size: 13px;
    color: #999;
  }

  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    padding: 0;
    float: right;
  }

  .image {
    width: 100%;
    height: 220px;
    display: block;
  }

  .clearfix:before,
  .clearfix:after {
      display: table;
      content: "";
  }

  .clearfix:after {
      clear: both
  }
</style>
